package com.ffyc.cms.service;

import com.ffyc.cms.dao.UserDao;
import com.ffyc.cms.model.User;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserService {
    @Autowired
    UserDao userDao;

    public User login(User user) {
        user.setPassword(DigestUtils.md5Hex(user.getPassword()));
        return userDao.login(user);
    }

    public void saveUser(User user) {
        //密码加密     获取密码
        String password = DigestUtils.md5Hex(user.getPassword());
        user.setPassword(password);
        //2.存储管理员信息, 返回管理员id
        userDao.insertUser(user);
    }

    public User findUserMsg(String account) {
        return userDao.findUserMsg(account);
    }

    public void updateUserMsg(User user) {
        userDao.updateUserMsg(user);
    }

    public User checkPwd(User user) {
        user.setPassword(DigestUtils.md5Hex(user.getPassword()));
        return userDao.checkPwd(user);
    }

    public void updateUserPwd(User user) {
        user.setPassword(DigestUtils.md5Hex(user.getPassword()));
        userDao.updateUserPwd(user);
    }

    public List<User> getUserList() {
        return userDao.getUserList();
    }

    public void updateaccstate(Integer id, Integer accstate) {
        userDao.updateaccstate(id,accstate);
    }
}
